//
//  HQNotiCell.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/5/5.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQNotiCell.h"

@implementation HQNotiCell

/**
 生成Cell
 
 @param tableView 列表
 @return ***
 */
+(instancetype)cellWithTableView:(UITableView*)tableView{
    static NSString *CellIdentifer = @"HQNotiCell";
    HQNotiCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer];
    if(!cell){
        [tableView registerNib:[UINib nibWithNibName:CellIdentifer bundle:nil] forCellReuseIdentifier:CellIdentifer];
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)setDataInfo:(id)dataInfo{
    _dataInfo = dataInfo;
    _acceptItem.dataInfo = dataInfo;
    _rejectItem.dataInfo = dataInfo;
    _itemTitle.text = _dataInfo[@"title"];
    _itemDetail.text = _dataInfo[@"content"];
    
    NSString *intervalString = _dataInfo[@"create_time"];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[intervalString doubleValue]+3600*8];// 加上八小时的时间差值
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm";
    NSString *string = [fmt stringFromDate:date];
    _itemTime.text = string;
    
    // 已读未读类型
    if([_dataInfo[@"state"]integerValue] == 2){
        // 2未读
        self.redMark.hidden = NO;
    }else if([_dataInfo[@"state"]integerValue] == 1){
        // 1已读
        self.redMark.hidden = YES;
    }
    
    // 消息类型
    if([_dataInfo[@"msgtype"]integerValue] == 1){
        // 普通消息
        _bottomView.hidden = YES;
        _bottomConstraint.constant = 0;
    }else if([_dataInfo[@"msgtype"]integerValue] == 2){
        // 合作邀请消息类型处理
        if([_dataInfo[@"state"]integerValue] == 2){
            // 未处理的的消息需要显示操作按钮
            _bottomConstraint.constant = 30;
            _bottomView.hidden = NO;
        }else{
            // 已处理的消息需要隐藏操作按钮
            _bottomConstraint.constant = 0;
            _bottomView.hidden = YES;
        }
    }else{
        _bottomView.hidden = YES;
        _bottomConstraint.constant = 0;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
